// pages/live-video/live-video.js
function getRandomColor() {
  let rgb = []
  for (let i = 0; i < 3; ++i) {
    let color = Math.floor(Math.random() * 256).toString(16)
    color = color.length == 1 ? '0' + color : color
    rgb.push(color)
  }
  return '#' + rgb.join('')
}
Page({
  onReady: function (res) {
    this.videoContext = wx.createVideoContext('myVideo')
  },
  inputValue: '',
  /**
   * 页面的初始数据
   */
  data: {
    showPopup:false,
    cancalBtnText:'取消',
    confirmBtnText:'确定',
    title:'你确认要结束直播吗？',
    src: '',
    danmuList: [
      {
        text: 'lalallalall真帅',
        color: '#ff0000',
        time: 1
      },
      {
        text: 'lalalallalllala',
        color: '#ff00ff',
        time: 2
      },
       {
        text: 'dkaosdfskdfksadf',
        color: '#ff0000',
        time: 3
      },
      {
        text: '海哥海哥海哥真帅',
        color: '#ff00ff',
        time: 4
      }
      ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },
  closeLiveVideo:function(){
    console.log('wodoanjile ')
    var that = this ;
    that.setData({
      showPopup:true
    })
  },
  clickBtn:function(e){
   console.log(e)
   var that = this;
   if(e.detail.type=="取消"){
     that.setData({
       showPopup: false
     })
   }else{
     that.setData({
       showPopup: false
     });
     wx:wx.navigateBack({
       delta: 1
     })
   }
  },
  bindInputBlur: function (e) {
    this.inputValue = e.detail.value
  },
  bindButtonTap: function () {
    var that = this
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      maxDuration: 60,
      camera: ['front', 'back'],
      success: function (res) {
        that.setData({
          src: res.tempFilePath
        })
      }
    })
  },
  bindSendDanmu: function () {
    this.videoContext.sendDanmu({
      text: this.inputValue,
      color: getRandomColor()
    })
  },
  
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})